package com.example.lemis.web.controller;

import com.example.lemis.model.dto.PageDTO;
import com.example.lemis.model.dto.StreetInsertDTO;
import com.example.lemis.model.dto.StreetQuery;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import com.example.lemis.common.JsonResponse;
import com.example.lemis.service.IStreetService;
import com.example.lemis.model.domain.Street;


/**
 * 前端控制器
 *
 * @author lxp
 * @version v1.0
 * @since 2025-06-24
 */
@RestController
@RequestMapping("/api/street")
@AllArgsConstructor
public class StreetController {

    private final Logger logger = LoggerFactory.getLogger(StreetController.class);

    private final IStreetService streetService;


    /**
     * 描述：根据Id 查询
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public JsonResponse<Street> getById(@PathVariable("id") Long id) throws Exception {
        Street street = streetService.getById(id);
        return JsonResponse.success(street);
    }

    @GetMapping
    public JsonResponse<?> getStreetWithDivision(StreetQuery streetQuery, PageDTO pageDTO) throws Exception {
        return JsonResponse.success(streetService.queryPageWithDivision(streetQuery, pageDTO));
    }


    @PostMapping("/{divisionId}")
    public JsonResponse<?> insertStreet(@PathVariable("divisionId") Long divisionId,
                                        @Validated @RequestBody StreetInsertDTO streetRequest)
            throws Exception {
        int lines = streetService.insert(divisionId, streetRequest);
        return JsonResponse.success(lines);
    }
}

